package com.lagou.utils;

import java.util.*;

/**
 * @author zy
 * @version 1.0
 * @date 2021/2/4 22:13
 */
public class getMap {

    public static String accordingToOrder(Map<String,Long> map){

        //这里将map.entrySet()转换成list
        List<Map.Entry<String, Long>> list = new ArrayList<Map.Entry<String, Long>>(map.entrySet());
        //然后通过比较器来实现排序
        Collections.sort(list, new Comparator<Map.Entry<String, Long>>() {
            //升序排序
            public int compare(Map.Entry<String, Long> o1,
                               Map.Entry<String, Long> o2) {
                return o1.getValue().compareTo(o2.getValue());
            }
        });
        return  list.get(0).getKey();
    }

}
